package com.res.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.res.entity.Teacher;
import com.res.service.TeacherService;
import com.res.util.FenyeUtil;

@RestController
@RequestMapping("/teacher")
public class TeacherController {
	@Autowired
	private TeacherService teacherService;

	@GetMapping
	public Object getAll(Teacher t, Integer tid, Integer limit, Integer page) {
		Pageable pageable = PageRequest.of(page-1, 10);
		FenyeUtil<Teacher> f = new FenyeUtil<Teacher>();
		f.setData(teacherService.getTeacherAll(t, pageable, tid).getContent());
		f.setCount((int) teacherService.getTeacherAll(t, pageable, tid).getTotalElements());
		return f;
	}

	@PostMapping
	public Object addTeacher(Teacher t, Integer tid) {
		return teacherService.addTeacher(t, tid);
	}

	@PutMapping
	public Object updateTeacher(Teacher t, Integer tid) {
		return teacherService.updateTeacher(t, tid);
	}

	@DeleteMapping
	public Object deleteTeacher(Integer tid) {
		return teacherService.deleteTeacher(tid);
	}
}
